<template>
  <div class="app-container">
    <el-row :gutter="20">
      <el-col class="aaa" :span="show ? rowObj.T1 : rowObj.F1" :xs="show ? rowObj.T2 : rowObj.F2">
        <workSiteLeft ref="workSiteLeft" :show="show" @showLeft="showLeft" @queryVal="queryVal" />
      </el-col>
      <el-col :span="show ? rowObj.T3 : rowObj.F3" :xs="show ? rowObj.T4 : rowObj.F4">
        <el-form :model="queryParams" ref="queryForm" size="mini" :inline="true" v-show="showSearch" label-width="68px" style="display: flex;justify-content: space-between;">
          <div>
            <el-button style="margin-right: 6px" size="mini" :icon="show ? 'el-icon-s-fold' : 'el-icon-s-unfold'" circle @click="showLeft(show)"></el-button>

            <el-form-item label="拌合站">
<!--              <el-input v-model="queryParams.stationName" placeholder="拌合站" clearable @keyup.enter.native="handleQuery" />-->
              <el-select
                style="width: 160px"
                v-model="queryParams.stationCode"
                clearable
                size="mini"
                placeholder="请选择拌合楼"
              >
                <el-option
                  v-for="item in cementListData"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                >
                </el-option>
              </el-select>
            </el-form-item>

            <el-form-item>
              <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
              <!-- <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button> -->
            </el-form-item>
          </div>
          <el-form-item>
            <el-button type="success" icon="el-icon-plus" size="mini" @click="handleAdd">新增</el-button>
          </el-form-item>
        </el-form>

        <el-table v-loading="loading" :data="cementDataList" :header-cell-style="{ 'text-align': 'center' }" fit border size="mini" highlight-current-row stripe>
          <el-table-column prop="stationName" label="拌合站" align="center" min-width="150px" :show-overflow-tooltip="true" fixed>
            <template slot-scope="scope">
              <span>{{ scope.row.stationName || "-" }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="gravel1Min" label="骨料1下限" align="center" min-width="90px" show-overflow-tooltip></el-table-column>
          <el-table-column prop="gravel1Max" label="骨料1上限" align="center" min-width="90px" show-overflow-tooltip></el-table-column>
          <el-table-column prop="gravel2Min" label="骨料2下限" align="center" min-width="90px" show-overflow-tooltip></el-table-column>
          <el-table-column prop="gravel2Max" label="骨料2上限" align="center" min-width="90px" show-overflow-tooltip></el-table-column>
          <el-table-column prop="gravel3Min" label="骨料3下限" align="center" min-width="90px" show-overflow-tooltip></el-table-column>
          <el-table-column prop="gravel3Max" label="骨料3上限" align="center" min-width="90px" show-overflow-tooltip></el-table-column>
          <el-table-column prop="gravel4Min" label="骨料4下限" align="center" min-width="90px" show-overflow-tooltip></el-table-column>
          <el-table-column prop="gravel4Max" label="骨料4上限" align="center" min-width="90px" show-overflow-tooltip></el-table-column>
          <el-table-column prop="gravel5Min" label="骨料5下限" align="center" min-width="90px" show-overflow-tooltip></el-table-column>
          <el-table-column prop="gravel5Max" label="骨料5上限" align="center" min-width="90px" show-overflow-tooltip></el-table-column>
          <el-table-column prop="gravel6Min" label="骨料6下限" align="center" min-width="90px" show-overflow-tooltip></el-table-column>
          <el-table-column prop="gravel6Max" label="骨料6上限" align="center" min-width="90px" show-overflow-tooltip></el-table-column>
          <el-table-column prop="powder1Min" label="粉料1下限" align="center" min-width="90px" show-overflow-tooltip></el-table-column>
          <el-table-column prop="powder1Max" label="粉料1上限" align="center" min-width="90px" show-overflow-tooltip></el-table-column>
          <el-table-column prop="powder2Min" label="粉料2下限" align="center" min-width="90px" show-overflow-tooltip></el-table-column>
          <el-table-column prop="powder2Max" label="粉料2上限" align="center" min-width="90px" show-overflow-tooltip></el-table-column>
          <el-table-column prop="waterMin" label="水含量下限" align="center" min-width="90px" show-overflow-tooltip></el-table-column>
          <el-table-column prop="waterMax" label="水含量上限" align="center" min-width="90px" show-overflow-tooltip></el-table-column>
          <el-table-column prop="sjbMin" label="水胶比下限" align="center" min-width="90px" show-overflow-tooltip></el-table-column>
          <el-table-column prop="sjbMax" label="水胶比上限" align="center" min-width="90px" show-overflow-tooltip></el-table-column>
          <el-table-column prop="status" label="启用/停用" align="center" show-overflow-tooltip fixed="right">
<!--            <template slot-scope="scope">-->
<!--              <el-tag v-if="scope.row.status == '1'" type="success">启用</el-tag>-->
<!--              <el-tag v-else type="danger">停用</el-tag>-->
<!--            </template>-->
            <template slot-scope="scope">
              <el-switch
                v-model="scope.row.status"
                active-color="#13ce66"
                inactive-color="#ff4949"
                active-value="1"
                inactive-value="0"
                @change="changeStatus(scope.row)">
              </el-switch>
            </template>
          </el-table-column>
          <el-table-column label="操作" align="center" width="100px" fixed="right">
            <template slot-scope="scope">
              <el-link type="primary" @click="handleEdit(scope.row)">编辑</el-link>
              <el-divider direction="vertical"></el-divider>
              <el-link type="primary" @click="handleDelete(scope.row)">删除</el-link>
            </template>
          </el-table-column>
        </el-table>

        <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />
      </el-col>
    </el-row>

    <!-- 添加或修改对话框 -->
    <el-dialog :title="title" :visible.sync="open" :close-on-click-modal="false" :close-on-press-escape="false" width="50%" append-to-body>
      <el-form ref="editForm" :model="form" :rules="rules" :inline="true" label-width="130px" class="myForm" size="mini" v-loading="loading">
        <el-row>
          <el-col :span="24">
            <el-form-item label="拌合站" prop="stationCode">
<!--              <el-input v-model="form.stationName" placeholder="拌合站" />-->
              <el-select
                style="width: 300px;"
                v-model="form.stationCode"
                clearable
                size="mini"
                placeholder="请选择拌合站"
                @change="changeCode()"
              >
                <el-option
                  v-for="item in cementListData"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
<!--            <el-form-item label="启用/停用">-->
<!--              <el-switch-->
<!--                disabled-->
<!--                v-model="form.status"-->
<!--                active-color="#13ce66"-->
<!--                inactive-color="#ff4949"-->
<!--                active-value="1"-->
<!--                inactive-value="0">-->
<!--              </el-switch>-->
<!--            </el-form-item>-->
          </el-col>
        </el-row>
        <el-row>
          <el-form-item label="骨料1下限">
            <el-input type="number" v-model="form.gravel1Min" placeholder="骨料1下限" >
              <template slot="suffix">%</template>
            </el-input>
          </el-form-item>
          <el-form-item label="骨料1上限">
            <el-input type="number" v-model="form.gravel1Max" placeholder="骨料1上限" >
              <template slot="suffix">%</template>
            </el-input>
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item label="骨料2下限">
            <el-input type="number" v-model="form.gravel2Min" placeholder="骨料2下限" >
              <template slot="suffix">%</template>
            </el-input>
          </el-form-item>
          <el-form-item label="骨料2上限">
            <el-input type="number" v-model="form.gravel2Max" placeholder="骨料2上限" >
              <template slot="suffix">%</template>
            </el-input>
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item label="骨料3下限">
            <el-input type="number" v-model="form.gravel3Min" placeholder="骨料3下限" >
              <template slot="suffix">%</template>
            </el-input>
          </el-form-item>
          <el-form-item label="骨料3上限">
            <el-input type="number" v-model="form.gravel3Max" placeholder="骨料3上限" >
              <template slot="suffix">%</template>
            </el-input>
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item label="骨料4下限">
            <el-input type="number" v-model="form.gravel4Min" placeholder="骨料4下限" >
              <template slot="suffix">%</template>
            </el-input>
          </el-form-item>
          <el-form-item label="骨料4上限">
            <el-input type="number" v-model="form.gravel4Max" placeholder="骨料4上限" >
              <template slot="suffix">%</template>
            </el-input>
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item label="骨料5下限">
            <el-input type="number" v-model="form.gravel5Min" placeholder="骨料5下限" >
              <template slot="suffix">%</template>
            </el-input>
          </el-form-item>
          <el-form-item label="骨料5上限">
            <el-input type="number" v-model="form.gravel5Max" placeholder="骨料5上限" >
              <template slot="suffix">%</template>
            </el-input>
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item label="骨料6下限">
            <el-input type="number" v-model="form.gravel6Min" placeholder="骨料6下限" >
              <template slot="suffix">%</template>
            </el-input>
          </el-form-item>
          <el-form-item label="骨料6上限">
            <el-input type="number" v-model="form.gravel6Max" placeholder="骨料6上限" >
              <template slot="suffix">%</template>
            </el-input>
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item label="粉料1下限">
            <el-input type="number" v-model="form.powder1Min" placeholder="粉料1下限" >
              <template slot="suffix">%</template>
            </el-input>
          </el-form-item>
          <el-form-item label="粉料1上限">
            <el-input type="number" v-model="form.powder1Max" placeholder="粉料1上限" >
              <template slot="suffix">%</template>
            </el-input>
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item label="粉料2下限">
            <el-input type="number" v-model="form.powder2Min" placeholder="粉料2下限" >
              <template slot="suffix">%</template>
            </el-input>
          </el-form-item>
          <el-form-item label="粉料2上限">
            <el-input type="number" v-model="form.powder2Max" placeholder="粉料2上限" >
              <template slot="suffix">%</template>
            </el-input>
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item label="水含量下限">
            <el-input type="number" v-model="form.waterMin" placeholder="水含量下限" >
              <template slot="suffix">%</template>
            </el-input>
          </el-form-item>
          <el-form-item label="水含量上限">
            <el-input type="number" v-model="form.waterMax" placeholder="水含量上限" >
              <template slot="suffix">%</template>
            </el-input>
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item label="水胶比上限">
            <el-input type="number" v-model="form.sjbMin" placeholder="水含量下限" >
              <template slot="suffix">%</template>
            </el-input>
          </el-form-item>
          <el-form-item label="水胶比下限">
            <el-input type="number" v-model="form.sjbMax" placeholder="水含量上限" >
              <template slot="suffix">%</template>
            </el-input>
          </el-form-item>
        </el-row>
      </el-form>
      <span slot="footer">
        <el-button size="mini" @click="cancel">取消</el-button>
        <el-button type="primary" size="mini" @click="submitForm" :loading="btnLoading">确定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import workSiteLeft from "@/views/components/workSiteLeft";
import { cements } from "@/api/waterStability/producedData/monitor";
import { nCementMatchList, nCementMatchInfo, addNCementMatch, nCementMatchEdit, nCementMatchRemove, getEnabledInfo }
from "@/api/waterStability/designMatching";

// import deatetime from "@/components/Datetime";

export default {
  name: "designMatching", //设计生产配比,
  components: {
    // deatetime,
    workSiteLeft
  },
  data() {
    return {
      show: true,
      rowObj: {
        T1: 3,
        T2: 24,
        T3: 21,
        T4: 24,
        F1: 0,
        F2: 0,
        F3: 24,
        F4: 24,
      },
      btnLoading: false,
      isEdit: false,
      materielProjectSelectList: [], //所属项目
      cementPavingLevelList: [], //摊铺层级
      waterMixrueList: [], //集科1——6
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      cementListData: [], //拌合楼列表
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 水稳拌合站数据表格数据
      cementDataList: [],
      // 查询参数
      queryParams: {
        // stationCode: null,
        stationName: null,
        pageNum: 1,
        pageSize: 10,
      },
      deptId: null,
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        station: [
          { required: true, message: "请选择拌合站", trigger: "change" },
        ],
      },
    };
  },
  filters: {
    /*** 显示集料或粉料信息 */
    showGravelAndPowder(val) {
      let property = val.column.property;
      let data = val.row;
      let value = data[property];
      if (null == value || undefined == value) {
        return "/";
      }
      let name = data[property + "Name"];
      if (null != name && undefined != name) {
        name += ":";
      } else {
        name = "";
      }
      return name + value;
    },
    /*** 显示数字 */
    showNumber(val) {
      if (null == val || undefined == val) {
        return "/";
      }
      return val;
    },
  },
  created() {
    this.getCementList();
    this.getList();
  },
  methods: {
    showLeft(show) {
      this.show = !show;
    },
    queryVal(val) {
      this.deptId = val.id;
      this.queryParams.id = val.id;
      this.handleQuery();
    },
    // 查询拌合楼下拉列表
    getCementList() {
      cements().then((res) => {
        this.cementListData = res.data || [];
      });
    },
    /** 查询水稳拌合站数据列表 */
    getList() {
      this.loading = true;
      nCementMatchList(this.queryParams).then((response) => {
        this.cementDataList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      // this.queryParams.stationCode = null;
      this.queryParams.stationName = null;
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 新增
    handleAdd() {
      // 选择组织机构后允许添加
      if (!this.deptId) {
        this.$message({
          type: "info",
          message: "请先选择左侧组织机构",
        });
        return false;
      }
      this.form = {};
      this.form.status = '0';
      this.isEdit = false;
      this.open = true;
      this.title = "添加生产配比";
    },
    // 编辑
    handleEdit(row) {
      this.form = row || {};
      this.isEdit = true;
      this.open = true;
      this.title = "修改生产配比";
    },
    handleDelete(row) {
      this.$confirm("此操作将删除该条数据, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
      .then(() => {
        nCementMatchRemove(row.id).then((res) => {
          this.getList();
          this.$message({
            type: "success",
            message: "删除成功!",
          });
        });
      })
      .catch(() => {
        this.$message({
          type: "info",
          message: "已取消删除",
        });
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.btnLoading = true;
      this.$refs["editForm"].validate((valid) => {
        if (valid) {
          // this.form.stationCode = "111";
          console.log(this.form);
          if (this.form.id) {
            nCementMatchEdit(this.form).then((res) => {
              this.$message.success("修改生产配比成功！");
              this.getList();
              this.btnLoading = false;
              this.open = false;
            });
          } else {
            this.$set(this.form, 'deptId', this.deptId);
            addNCementMatch(this.form).then((res) => {
              this.$message.success("新增生产配比成功！");
              this.getList();
              this.btnLoading = false;
              this.open = false;
            });
          }
        } else {
          this.btnLoading = false;
        }
      });
    },
    cancel() {
      this.getList();
      this.open = false;
    },
    // 状态改变
    changeStatus(row) {
      nCementMatchEdit(row).then((res) => {
        this.$message.success("修改成功！");
        this.getList();
      });
    },
    changeCode(val) {
      console.log(111, val)
    }
  },
};
</script>
<!-- <style scoped lang="scss">
.app-designMatching {
  padding-top: 16px;
  user-select: none;
}
</style> -->

<style scoped>
.myForm>>>.el-input-number {
  width: 100%;
}

.myForm>>>.el-input__inner {
  text-align: left;
}

.myForm>>>.el-input-number {
  width: 100%;
}

.myForm>>>.el-input__inner {
  text-align: left;
}

.form-item-out {
  margin-bottom: 0px;
}

.colSplit {
  text-align: center;
  font-size: 16px;
}

.el-col {
  border: 1px solid transparent;
}

.descriptionsBox>>>div {
  text-align: center;
  font-size: 20px;
  font-weight: 400;
}

.descriptionsBox>>>.descriptionsDiv {
  /* border-bottom: 2px solid #e6ebf5; */
  border-bottom: 1px solid #e6ebf5;
}
</style>

